package com.bfly.mall.advert.service.impl;

import com.bfly.core.base.service.BaseServiceImpl;
import com.bfly.core.enums.SysError;
import com.bfly.core.exception.ServiceResponseException;
import com.bfly.mall.advert.entity.AdvertType;
import com.bfly.mall.advert.dto.AdvertTypeFormDTO;
import com.bfly.mall.advert.service.IAdvertTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author 长沙商脉科技有限公司
 * @date 2020/9/18 22:41
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS)
public class AdvertTypeServiceImpl extends BaseServiceImpl<AdvertType, Integer> implements IAdvertTypeService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(AdvertTypeFormDTO formDTO) {
        AdvertType type = new AdvertType();
        type.setName(formDTO.getName());
        type.setCreateDate(new Date());
        super.save(type);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void edit(AdvertTypeFormDTO formDTO) {
        AdvertType type = get(formDTO.getId());
        if (type == null) {
            throw new ServiceResponseException(SysError.PARAM_ERROR, "不存在的广告类型信息!");
        }
        type.setName(formDTO.getName());
        type.setUpdateDate(new Date());
        super.edit(type);
    }
}
